import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_ui/lib_ui.dart';
import 'package:lib_ui/widget/main_button.dart';

import '../../routes/get_routes.dart';
import 'controller_test.dart';

class ControllerTest3Page extends StatefulWidget {
  const ControllerTest3Page({super.key});

  @override
  State<ControllerTest3Page> createState() => _ControllerTest3PageState();
}

class _ControllerTest3PageState extends State<ControllerTest3Page> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TransparentAppBar(title: 'controller注入'),
      body: SizedBox(
        width: Get.width,
        child: Column(
          children: [
            MainButton(
              text: '通过find获取controller，并赋值20',
              onClick: () {
                try {
                  final controller = Get.find<ControllerTest>();
                  controller.num = 20;
                  'controller找到了，num = ${controller.num}'.showInfo();
                } catch (e) {
                  'controller找不到'.showError();
                }
              },
            ),
            MainButton(
              text: '返回到ControllerTest1页面',
              onClick: () {
                GetRoutes.controllerTest1.popUntil();
              },
            ),
          ],
        ),
      ),
    );
  }
}
